package rcs34.android.AndroidRC;

import java.util.TimerTask;

import android.os.Handler;

public class ATimer {
  private Handler handler;
  private TimerTask task;
  private long timeout;
  boolean alive;

  public ATimer() {
    handler = new Handler();
  }

  synchronized public void reset() {
    if (alive) {
      handler.removeCallbacksAndMessages(null);
      handler.postDelayed(task, timeout);
    }
  }

  synchronized public void setUp(TimerTask _task, long _timeout) {
    alive=true;
    task = _task;
    timeout = _timeout;
    reset();
  }

  synchronized public void cancel() {
    handler.removeCallbacksAndMessages(null);
    alive = false;
  }
}